// pages/addhuanzhexinxi/addhuanzhexinxi.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sex1: [{
        name: '男',
        value: '0',
        checked: 'true'
      },
      {
        name: '女',
        value: '1'
      },
    ],
    have: [{
        name: '有',
        value: '1',
        checked: 'true'
      },
      {
        name: '无',
        value: '0'
      },
    ],
    date: '',
    textarea: '',
    sex: 1,
    guomin: 1,
  },
  // 性别
  sexChange(e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)
    let t = this;
    t.setData({
      sex: e.detail.value
    })
  },
  // 过敏史
  radioChange(e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)
    let t = this;
    t.setData({
      guomin: e.detail.value
    })
  },
  // 时间选择
  bindDateChange(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },
  // 病史内容
  getTextarea: function(e) {
    let t = this;
    t.setData({
      textarea: e.detail.value
    })
  },
  // 提交表单
  addhuanzhe: function(e) {
    console.log(e);
    var that = this
    var stateinfo = that.data.stateinfo
    var oid = that.data.oid
    var num = that.data.num
    var zid = that.data.zid
    app.util.request({
      'url': 'entry/wxapp/Addtijian',
      data: {
        openid: wx.getStorageSync('openid'),
        datetime: e.detail.value.datetime,
        guomin: e.detail.value.guomin,
        history: e.detail.value.history,
        kg: e.detail.value.kg,
        names: e.detail.value.names,
        sex: e.detail.value.sex,
        age: e.detail.value.age
      },
      success: function(res) {
        console.log(res)
        wx.showToast({
          title: '添加成功',
          icon: 'none',
          duration: 1500,
          success: function() {
            wx.navigateTo({
              url: '/hyb_yl/zhuanjiasubpages/pages/huanzhezhifu/huanzhezhifu?zid=' + zid + '&stateinfo=' + state + '&oid=' + oid + '&num=' + num,
            })

          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var zid = options.zid
    var stateinfo = options.stateinfo
    var oid = options.oid
    var num = options.num
    that.setData({
      zid: zid,
      stateinfo: stateinfo,
      oid: oid,
      num: num
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    prevPage.setData({
      st: 1
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})